<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button onclick="xhr.abort();">取消</button>
    <script>
      const xhr = new XMLHttpRequest();
      xhr.open("GET", "http://localhost:3008/users");
      xhr.onreadystatechange = function () {
        // 定位到某个阶段取消
        // if (xhr.readyState === 2) {
        //   xhr.abort();
        // }
        // if (xhr.readyState === 3) {
        //   xhr.abort();
        // }
      };
      // 当请求被取消时触发
      xhr.onabort = function () {
        console.log("取消成功！");
      };
      xhr.onload = function () {
        console.log(xhr.response);
      };
      xhr.send();
    </script>
  </body>
</html>
